package com.jy.unkown.AD;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.pm.Signature;
import android.os.Build;
import android.text.TextUtils;
import android.util.Base64;

import com.jy.common.BaseApplication;
import com.jy.utils.cache.SpManager;
import com.jy.utils.utils.MD5;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;


public class APLiTool {




    public static String collectAppList() {
        List<ApplicationInfo> packageInfos = BaseApplication.getBaseApplication().getPackageManager().getInstalledApplications(0);
        StringBuffer stringBuffer=new StringBuffer();
        for (ApplicationInfo applicationInfo : packageInfos) {
            if (isSystemApp(applicationInfo)||isSystemApplication(applicationInfo)){

            }else {
                stringBuffer.append(applicationInfo.packageName).append(",");
            }
        }
        return stringBuffer.toString();
    }


    public static boolean isSystemApplication(ApplicationInfo app) {
        try {
            return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    // 通过packName得到PackageInfo，作为参数传入即可
    public static boolean isSystemApp(ApplicationInfo pi) {
        boolean isSysApp = (pi.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
        boolean isSysUpd = (pi.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
        return isSysApp || isSysUpd;
    }
}
